<ui:composition xmlns="http://www.w3.org/1999/xhtml"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui" xmlns:f="http://java.sun.com/jsf/core"
                xmlns:constants="http://www.tuanzi.com/constants/tags"
                xmlns:security="http://www.springframework.org/security/tags"
                template="/templates/template.xhtml">
    <ui:define name="title">渠道主体</ui:define>
    <ui:define name="content">


        <h:form>
            <p:dialog header="操作执行中,请稍候" widgetVar="doing" modal="true" closable="false" resizable="false"
                      draggable="false"/>
            <p:defaultCommand target="search"/>
            <div class="topbar clearfix" style="background: -webkit-linear-gradient(top,#f6f7f9 0,#ebedf0 100%);">
                <p:toolbar>
                    <f:facet name="left">
                        <p:commandButton id="toggler" type="button" value="展示选择"
                                         style="width: auto;"
                                         icon="ui-icon-calculator"/>
                        <p:columnToggler datasource="statisticRecordDataTable" trigger="toggler"/>
                    </f:facet>
                    <f:facet name="right">
                        <p:commandButton value="新增" action="#{businessMainListBean.onAdd}"
                                         icon="fa fa-plus"
                                         process="@this" rendered="#{security:areAllGranted('BUSINESS_SECURITY')}">
                            <f:setPropertyActionListener
                                    value="/views/businesssystem/main-list.xhtml"
                                    target="#{currentUserBean.back}"/>
                        </p:commandButton>
                        <p:commandButton id="search" value="查询" icon="fa fa-search"
                                         onstart="PF('doing').show()"
                                         update="@form"/>
                        <p:commandButton value="重置" actionListener="#{businessMainListBean.onReset()}" icon="fa fa-refresh"
                                         process="@this" update="@form"/>
                        <p:commandButton value="导出" icon="fa fa-download"
                                         ajax="false">
                            <p:dataExporter type="xls" target="statisticRecordDataTable" fileName="主体信息" postProcessor="#{businessMainListBean.postProcessXLS}"/>
                        </p:commandButton>
                    </f:facet>
                </p:toolbar>
            </div>
            <div class="ui-g ui-fluid" style="padding-top: 30px;">
                <div class="ui-g-12">
                    <div class="ui-g-12 card">
                        <h1>查询条件</h1>
                        <div class="ui-g-2">
                            <p:outputLabel value="结算时间"/>
                        </div>
                        <div class="ui-g-4">
                            <p:calendar
                                    id="startTime" styleClass="autoWidthCalendar"
                                    value="#{businessMainListBean.$.startTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATE_FORMAT')}"/>
                            <span>—</span>
                            <p:calendar
                                    id="endTime" styleClass="autoWidthCalendar"
                                    value="#{businessMainListBean.$.endTime}"
                                    locale="#{constants:get('LOCALE')}"
                                    timeZone="#{constants:get('TIME_ZONE')}"
                                    pattern="#{constants:get('DATE_FORMAT')}"/>
                        </div>
                        <div class="ui-g-2">
                            <p:outputLabel value="渠道主体"/>
                        </div>
                        <div class="ui-g-4">
                            <p:inputText id="companyName" value="#{businessMainListBean.$.mainName}"/>
                        </div>
                        <div class="ui-g-2">
                            <p:outputLabel value="主体类型"/>
                        </div>
                        <div class="ui-g-4">
                            <p:selectOneMenu id="mainType" value="#{businessMainListBean.$.mainType}">
                                <f:selectItem itemLabel="- 请选择 -" itemValue=""
                                              noSelectionOption="true"/>
                                <f:selectItems value="#{businessMainListBean.dictionaries[DictionaryCode.BUSINESS_MAIN_TYPE]}"
                                               var="dic"
                                               itemLabel="#{dic.name}" itemValue="#{dic.value1}"/>
                            </p:selectOneMenu>
                        </div>
                        <div class="ui-g-2">
                            <p:outputLabel value="创建人"/>
                        </div>
                        <div class="ui-g-4">
                            <p:inputText id="creator" value="#{businessMainListBean.$.creator}"/>
                        </div>

                        <div class="ui-g-12 card">
                            <p:dataTable id="statisticRecordDataTable"
                                         style="width: 120%;text-align:center"
                                         var="record"
                                         value="#{businessMainListBean.lazyDataModel}"
                                         rows="#{constants:get('ROWS')}"
                                         lazy="true"
                                         paginator="true"
                                         paginatorTemplate="#{constants:get('PAGINATOR_TEMPLATE')}"
                                         rowsPerPageTemplate="#{constants:get('ROWS_PER_PAGE_TEMPLATE')}"
                                         emptyMessage="#{constants:get('EMPTY_MESSAGE')}"
                                         scrollable="true"
                                         scrollWidth="97%"
                                         reflow="true"
                                         selection=""
                                         resizableColumns="true">
                                <p:column headerText="操作" rendered="#{security:areAllGranted('BUSINESS_SECURITY')}">
                                    <p:splitButton icon="fa fa-eye"
                                                   process="@this" action="#{businessMainListBean.onSee(record.id)}" rendered="#{security:areAllGranted('BUSINESS_SECURITY')}">
                                        <f:setPropertyActionListener
                                                value="/views/businesssystem/main-list.xhtml"
                                                target="#{currentUserBean.back}"/>
                                        <p:menuitem value="删除" icon="fa fa-remove"
                                                    actionListener="#{businessMainListBean.onDelete(record.id)}"
                                                    process="@this" update="@form" rendered="#{security:areAllGranted('BUSINESS_SECURITY')}">
                                            <p:confirm header="提示信息" message="是否确定删除?" icon="ui-icon-alert"/>
                                        </p:menuitem>
                                    </p:splitButton>
                                </p:column>
                                <p:column headerText="渠道主体" style="width: 250px">
                                    <h:outputText value="#{record.companyName}"/>
                                </p:column>
                                <p:column headerText="主体类型" style="text-align:center;">
                                    <h:outputText value="#{businessMainListBean.translate(DictionaryCode.BUSINESS_MAIN_TYPE,record.mainType)}"/>
                                </p:column>
                                <p:column headerText="纳税人识别号" style="text-align:center;">
                                    <h:outputText value="#{record.idCode}"/>
                                </p:column>
                                <p:column headerText="开户行" style="text-align:center;">
                                    <h:outputText value="#{record.bank}"/>
                                </p:column>
                                <p:column headerText="账号" style="text-align:center;">
                                    <h:outputText value="#{record.bankId}"/>
                                </p:column>
                                <p:column headerText="垫付金额" style="text-align:center;">
                                    <h:outputText value="#{record.advancePay==null?0:record.advancePay}">
                                        <f:convertNumber pattern="###0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="付款金额" style="text-align:center;">
                                    <h:outputText value="#{record.prepayAmount==null?0:record.prepayAmount}">
                                        <f:convertNumber pattern="###0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="返点金额" style="text-align:center;">
                                    <h:outputText value="#{record.returnPay==null?0:record.returnPay}">
                                        <f:convertNumber pattern="###0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="消耗金额" style="text-align:center;">
                                    <h:outputText value="#{record.expendAmount==null?0:record.expendAmount}">
                                        <f:convertNumber pattern="###0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="剩余金额" style="text-align:center;">
                                    <h:outputText value="#{record.prepayAmount - record.expendAmount}">
                                        <f:convertNumber pattern="###0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="开票金额" style="text-align:center;">
                                    <h:outputText value="#{record.billAmount==null?0:record.billAmount}">
                                        <f:convertNumber pattern="###0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="剩余开票金额" style="text-align:center;">
                                    <h:outputText value="#{record.prepayAmount - record.billAmount}">
                                        <f:convertNumber pattern="###0.00"/>
                                    </h:outputText>
                                </p:column>
                                <p:column headerText="备注" style="text-align:center;width: 30px;">
                                    <h:outputText value="#{record.remark}"/>
                                </p:column>
                                <p:column headerText="创建人" style="text-align:center;">
                                    <h:outputText value="#{record.creator}"/>
                                </p:column>
                                <p:column headerText="创建时间" style="text-align:center;">
                                    <h:outputText value="#{record.createTime}">
                                        <f:convertDateTime pattern="#{constants:get('DATETIME_FORMAT')}"/>
                                    </h:outputText>
                                </p:column>
                            </p:dataTable>
                        </div>

                    </div>
                </div>
            </div>
        </h:form>
    </ui:define>
</ui:composition>